package com.dongnam.quanly.common.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import com.dongnam.quanly.common.ScreenType;
import com.dongnam.quanly.common.model.UserRight;
import com.dongnam.quanly.common.model.UserRole;

public class UserRightDao extends GenericDao<UserRight, Integer> {

	@SuppressWarnings("unchecked")
	public List<UserRight> findByType(ScreenType type) {
		Criteria crit = getSession().createCriteria(getPersistentClass());
		crit.add(Restrictions.eq("typeId", type));
		return crit.list();
	}

	public UserRight findByRoleAndType(UserRole role, ScreenType type) {
		Criteria crit = getSession().createCriteria(getPersistentClass());
		crit.add(Restrictions.eq("userRole", role));
		crit.add(Restrictions.eq("typeId", type));
		return (UserRight) crit.uniqueResult();
	}

	@SuppressWarnings("unchecked")
	public List<UserRight> findByRole(UserRole role) {
		Criteria crit = getSession().createCriteria(getPersistentClass());
		crit.add(Restrictions.eq("userRole", role));
		return crit.list();
	}

}
